import { defineConfig } from '@vben/vite-config';
import Components from 'unplugin-vue-components/vite'; // 按需加载自定义组件
import AutoImport from 'unplugin-auto-import/vite';
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers';

export default defineConfig(async () => {
  return {
    application: {},
    vite: {
      server: {
        proxy: {
          '/api': {
            changeOrigin: true,
            rewrite: (path) => path.replace(/^\/api/, ''),
            // mock代理目标地址
            target: 'http://localhost:5320/api',
            ws: true,
          },
        },
      },
      plugins: [
        // 自动导入api
        AutoImport({
          imports: [
            'vue',
            'vue-router',
            'pinia',
            'vue-i18n',
            '@vueuse/core',
            {
              'naive-ui': [
                'useDialog',
                'useMessage',
                'useNotification',
                'useLoadingBar',
              ],
            },
          ],
          dts: 'auto-import.d.ts',
          dirs: ['src/api/system', 'src/types'],
          vueTemplate: true, // 自动导入vue相关函数
        }),
        // 自动导入组件
        Components({
          dirs: ['src/component'],
          extensions: ['vue', 'ts'], //组件的扩展名
          deep: true, //搜索子目录
          dts: 'components.d.ts',
          resolvers: [NaiveUiResolver()],
        }),
      ],
    },
  };
});
